package com.tongtech.system.controller;

import com.tongtech.common.core.web.controller.BaseController;
import com.tongtech.common.core.web.domain.AjaxResult;
import com.tongtech.common.mail.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;
import java.util.HashMap;
import java.util.Map;


/**
 * 资讯分类信息
 *
 * @author xingyc
 */

@RestController
@RequestMapping("/mail")
public class MailController extends BaseController
{
    @Autowired
    private MailService mailService;

    /**
     * 根据资讯分类编号获取详细信息
     */
    @GetMapping
    public AjaxResult sendMail() throws MessagingException {
        String templateName = "news";
        boolean result = false;
        try {
            Map<String, String> params = new HashMap<String, String>();
            params.put("title", "你好，欢迎使用我们的系统！");
            mailService.sendMail("2095574892@qq.com", "xingyc@tongtech.com" , "邮件测试", templateName, params);
            result = true;
        } catch (MessagingException e) {
            e.printStackTrace();
            result = false;
        } catch (MailException e1){
            result = false;
        }
        if(result){
            return  AjaxResult.success("发送成功");
        }else{
            return AjaxResult.error("发送失败，请联系管理员。");
        }
    }
}
